package mysql

import (
	"gorm.io/gorm"
)

type Carl struct {
	gorm.Model
	UserId     int64   `gorm:"type:int(10);index;not null;comment:用户ID;"`
	GoodId     int64   `gorm:"type:int(10);index;not null;comment:商品ID;"`
	Num        int64   `gorm:"type:int(10);not null;comment:加入数量;"`
	GoodsPrice float64 `gorm:"type:decimal(10,2);not null;comment:价格;"`
	GoodsTitle string  `gorm:"type:varchar(50);not null;comment:商品名称;"`
	Checked    int64   `gorm:"type:tinyint(1);not null;default:1;comment:商品状态;"`
}

// 添加购物车
func (c *Carl) AddCarl() error {
	return DB.Create(&c).Error
}

// 购物车列表
func (c *Carl) List(userId int) (list []*Carl, err error) {
	err = DB.Where("user_id = ?", userId).Find(&list).Error
	return list, err
}
